/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.openams.server.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author mike
 */
@Entity
@Table(name = "datasetinstancehierarchy")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "DatasetInstanceHierarchy.findAll", query = "SELECT d FROM DatasetInstanceHierarchy d"),
    @NamedQuery(name = "DatasetInstanceHierarchy.findByDatasetInstanceHierarchyID", query = "SELECT d FROM DatasetInstanceHierarchy d WHERE d.datasetInstanceHierarchyID = :datasetInstanceHierarchyID"),
    @NamedQuery(name = "DatasetInstanceHierarchy.findByOrdinal", query = "SELECT d FROM DatasetInstanceHierarchy d WHERE d.ordinal = :ordinal")})
public class DatasetInstanceHierarchy implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "DatasetInstanceHierarchyID", nullable = false)
    private Integer datasetInstanceHierarchyID;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Ordinal", nullable = false)
    private int ordinal;
    @OneToMany(mappedBy = "referenceDatasetInstanceHierarchyID", fetch = FetchType.LAZY)
    private Collection<DatasetInstanceAssignment> datasetInstanceAssignmentCollection;
    @JoinColumn(name = "DatasetTemplateHierarchyID", referencedColumnName = "DatasetTemplateHierarchyID", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private DatasetTemplateHierarchy datasetTemplateHierarchyID;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "parentDatasetInstanceHierarchyID", fetch = FetchType.LAZY)
    private Collection<DatasetInstanceHierarchy> datasetInstanceHierarchyCollection;
    @JoinColumn(name = "ParentDatasetInstanceHierarchyID", referencedColumnName = "DatasetInstanceHierarchyID", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private DatasetInstanceHierarchy parentDatasetInstanceHierarchyID;
    @JoinColumn(name = "ChildDatasetInstanceID", referencedColumnName = "DatasetInstanceID", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private DatasetInstance childDatasetInstanceID;

    public DatasetInstanceHierarchy() {
    }

    public DatasetInstanceHierarchy(Integer datasetInstanceHierarchyID) {
        this.datasetInstanceHierarchyID = datasetInstanceHierarchyID;
    }

    public DatasetInstanceHierarchy(Integer datasetInstanceHierarchyID, int ordinal) {
        this.datasetInstanceHierarchyID = datasetInstanceHierarchyID;
        this.ordinal = ordinal;
    }

    public Integer getDatasetInstanceHierarchyID() {
        return datasetInstanceHierarchyID;
    }

    public void setDatasetInstanceHierarchyID(Integer datasetInstanceHierarchyID) {
        this.datasetInstanceHierarchyID = datasetInstanceHierarchyID;
    }

    public int getOrdinal() {
        return ordinal;
    }

    public void setOrdinal(int ordinal) {
        this.ordinal = ordinal;
    }

    @XmlTransient
    public Collection<DatasetInstanceAssignment> getDatasetInstanceAssignmentCollection() {
        return datasetInstanceAssignmentCollection;
    }

    public void setDatasetInstanceAssignmentCollection(Collection<DatasetInstanceAssignment> datasetInstanceAssignmentCollection) {
        this.datasetInstanceAssignmentCollection = datasetInstanceAssignmentCollection;
    }

    public DatasetTemplateHierarchy getDatasetTemplateHierarchyID() {
        return datasetTemplateHierarchyID;
    }

    public void setDatasetTemplateHierarchyID(DatasetTemplateHierarchy datasetTemplateHierarchyID) {
        this.datasetTemplateHierarchyID = datasetTemplateHierarchyID;
    }

    @XmlTransient
    public Collection<DatasetInstanceHierarchy> getDatasetInstanceHierarchyCollection() {
        return datasetInstanceHierarchyCollection;
    }

    public void setDatasetInstanceHierarchyCollection(Collection<DatasetInstanceHierarchy> datasetInstanceHierarchyCollection) {
        this.datasetInstanceHierarchyCollection = datasetInstanceHierarchyCollection;
    }

    public DatasetInstanceHierarchy getParentDatasetInstanceHierarchyID() {
        return parentDatasetInstanceHierarchyID;
    }

    public void setParentDatasetInstanceHierarchyID(DatasetInstanceHierarchy parentDatasetInstanceHierarchyID) {
        this.parentDatasetInstanceHierarchyID = parentDatasetInstanceHierarchyID;
    }

    public DatasetInstance getChildDatasetInstanceID() {
        return childDatasetInstanceID;
    }

    public void setChildDatasetInstanceID(DatasetInstance childDatasetInstanceID) {
        this.childDatasetInstanceID = childDatasetInstanceID;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (datasetInstanceHierarchyID != null ? datasetInstanceHierarchyID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DatasetInstanceHierarchy)) {
            return false;
        }
        DatasetInstanceHierarchy other = (DatasetInstanceHierarchy) object;
        if ((this.datasetInstanceHierarchyID == null && other.datasetInstanceHierarchyID != null) || (this.datasetInstanceHierarchyID != null && !this.datasetInstanceHierarchyID.equals(other.datasetInstanceHierarchyID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.openams.server.entity.DatasetInstanceHierarchy[ datasetInstanceHierarchyID=" + datasetInstanceHierarchyID + " ]";
    }
    
}
